<template>
  <div class="widget-section">
    <h4 class="section-name">页面控件</h4>
    <div class="widget-list">
      <div
        class="widget-item"
        v-for="(item, index) in widgetList"
        :key="index"
        :class="activeWidget == index ? 'activeWidget' : ''"
        @click.stop="editWidget(item, index)"
      >
        <span>{{ item.name }}</span>
        <i class="iconfont icon-mokuai-bianji"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    widgetList: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      activeWidget: -1,
    };
  },
  watch: {},
  computed: {},
  methods: {
    // 点击编辑
    editWidget(item, index) {
      console.log(item);
      this.activeWidget = index;
      this.$emit("editWidget", { item });
    },
  },
};
</script>

<style lang="scss" scoped>
.widget-section {
  width: 100%;
  .section-name {
    width: 100%;
    height: 60px;
    background: #ffffff;
    padding: 24px 24px 14px 24px;
    font-size: 16px;
    color: #000000;
    margin: 0;
  }
  .widget-list {
    width: 282px;
    margin: 8px auto 0;
    .widget-item {
      width: 280px;
      height: 40px;
      background: #ffffff;
      border: 1px solid #e8eaec;
      border-radius: 4px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
      font-size: 14px;
      font-weight: 400;
      color: #000000;
      padding: 0 14px;
      transition: all 0.2s;
      cursor: pointer;

      .iconfont {
        font-size: 17px;
        display: none;
      }
    }
    .widget-item:hover > .iconfont {
      display: inline-block;
    }
    .activeWidget {
      border: 1px solid #1890fc;
      color: #1890fc;
    }
  }
}
</style>
